From 891da626b07c0a3774a6f1c7acef14a4662094f7 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 20 Mar 2015 19:59:47 -0700 Subject: [PATCH] Don't compile build scripts if they aren't run --- src/cargo/ops/cargo_rustc/mod.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 7533e1166..aba4c6262 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -204,7 +204,6 @@ fn compile<'a, 'b>(targets: &[(&'a Target, &'a Profile)], // package is needed in both a host and target context, we need to run // it once per context. if !target.is_custom_build() { continue } - let run_custom = jobs.queue(pkg, Stage::RunCustomBuild); let mut reqs = Vec::new(); let requirement = pkg.targets().iter().filter(|t| !t.is_custom_build()) .fold(None::, |req, t| { @@ -223,8 +222,12 @@ fn compile<'a, 'b>(targets: &[(&'a Target, &'a Profile)], } } } + let before = jobs.queue(pkg, Stage::RunCustomBuild).len(); for &req in reqs.iter() { - let kind = match req { Platform::Plugin => Kind::Host, _ => Kind::Target }; + let kind = match req { + Platform::Plugin => Kind::Host, + _ => Kind::Target, + }; let key = (pkg.package_id().clone(), kind); if pkg.manifest().links().is_some() && cx.build_state.outputs.lock().unwrap().contains_key(&key) { @@ -232,8 +235,15 @@ fn compile<'a, 'b>(targets: &[(&'a Target, &'a Profile)], } let (dirty, fresh, freshness) = try!(custom_build::prepare(pkg, target, req, cx)); + let run_custom = jobs.queue(pkg, Stage::RunCustomBuild); run_custom.push((Job::new(dirty, fresh), freshness)); } + + // If we didn't actually run the custom build command, then there's no + // need to compile it. + if jobs.queue(pkg, Stage::RunCustomBuild).len() == before { + jobs.queue(pkg, Stage::BuildCustomBuild).pop(); + } } drop(profiling_marker); -- 2.30.2